

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/fluid.png">
  <link rel="icon" href="/img/fluid.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="hgc">
  <meta name="keywords" content="">
  
    <meta name="description" content="前言 本篇是《 Python编程从入门到实践 》一书的练习部分的代码 花费了些许时间，将这本书非项目实践部分看了一遍，因为有其他语言的基础，所以看起来相对来说不是很费劲。纸上得来终觉浅，觉知此事要躬行！加油！ 第二章 练习2.1 12val &#x3D; &quot;hello world&quot;print(val)  练习2.2 1234val &#x3D; &quot;hello world&quot;pri">
<meta property="og:type" content="article">
<meta property="og:title" content="Python编程从入门到实践练习题">
<meta property="og:url" content="http://example.com/2024/03/28/Python%E7%BC%96%E7%A8%8B%E4%BB%8E%E5%85%A5%E9%97%A8%E5%88%B0%E5%AE%9E%E8%B7%B5%E7%BB%83%E4%B9%A0%E9%A2%98/index.html">
<meta property="og:site_name" content="hgc&#39;s Blog">
<meta property="og:description" content="前言 本篇是《 Python编程从入门到实践 》一书的练习部分的代码 花费了些许时间，将这本书非项目实践部分看了一遍，因为有其他语言的基础，所以看起来相对来说不是很费劲。纸上得来终觉浅，觉知此事要躬行！加油！ 第二章 练习2.1 12val &#x3D; &quot;hello world&quot;print(val)  练习2.2 1234val &#x3D; &quot;hello world&quot;pri">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://example.com/2024/03/28/Python%E7%BC%96%E7%A8%8B%E4%BB%8E%E5%85%A5%E9%97%A8%E5%88%B0%E5%AE%9E%E8%B7%B5%E7%BB%83%E4%B9%A0%E9%A2%98/image-20240328192658637.png">
<meta property="og:image" content="http://example.com/2024/03/28/Python%E7%BC%96%E7%A8%8B%E4%BB%8E%E5%85%A5%E9%97%A8%E5%88%B0%E5%AE%9E%E8%B7%B5%E7%BB%83%E4%B9%A0%E9%A2%98/image-20240328192831111.png">
<meta property="og:image" content="http://example.com/2024/03/28/Python%E7%BC%96%E7%A8%8B%E4%BB%8E%E5%85%A5%E9%97%A8%E5%88%B0%E5%AE%9E%E8%B7%B5%E7%BB%83%E4%B9%A0%E9%A2%98/image-20240328193043760.png">
<meta property="og:image" content="http://example.com/2024/03/28/Python%E7%BC%96%E7%A8%8B%E4%BB%8E%E5%85%A5%E9%97%A8%E5%88%B0%E5%AE%9E%E8%B7%B5%E7%BB%83%E4%B9%A0%E9%A2%98/image-20240328193211082.png">
<meta property="og:image" content="http://example.com/2024/03/28/Python%E7%BC%96%E7%A8%8B%E4%BB%8E%E5%85%A5%E9%97%A8%E5%88%B0%E5%AE%9E%E8%B7%B5%E7%BB%83%E4%B9%A0%E9%A2%98/image-20240328193644393.png">
<meta property="og:image" content="http://example.com/2024/03/28/Python%E7%BC%96%E7%A8%8B%E4%BB%8E%E5%85%A5%E9%97%A8%E5%88%B0%E5%AE%9E%E8%B7%B5%E7%BB%83%E4%B9%A0%E9%A2%98/image-20240328193844302.png">
<meta property="og:image" content="http://example.com/2024/03/28/Python%E7%BC%96%E7%A8%8B%E4%BB%8E%E5%85%A5%E9%97%A8%E5%88%B0%E5%AE%9E%E8%B7%B5%E7%BB%83%E4%B9%A0%E9%A2%98/image-20240328194620513.png">
<meta property="og:image" content="http://example.com/2024/03/28/Python%E7%BC%96%E7%A8%8B%E4%BB%8E%E5%85%A5%E9%97%A8%E5%88%B0%E5%AE%9E%E8%B7%B5%E7%BB%83%E4%B9%A0%E9%A2%98/image-20240329105146608.png">
<meta property="og:image" content="http://example.com/2024/03/28/Python%E7%BC%96%E7%A8%8B%E4%BB%8E%E5%85%A5%E9%97%A8%E5%88%B0%E5%AE%9E%E8%B7%B5%E7%BB%83%E4%B9%A0%E9%A2%98/image-20240329155329532.png">
<meta property="og:image" content="http://example.com/2024/03/28/Python%E7%BC%96%E7%A8%8B%E4%BB%8E%E5%85%A5%E9%97%A8%E5%88%B0%E5%AE%9E%E8%B7%B5%E7%BB%83%E4%B9%A0%E9%A2%98/image-20240329163439454.png">
<meta property="og:image" content="http://example.com/2024/03/28/Python%E7%BC%96%E7%A8%8B%E4%BB%8E%E5%85%A5%E9%97%A8%E5%88%B0%E5%AE%9E%E8%B7%B5%E7%BB%83%E4%B9%A0%E9%A2%98/image-20240329163951830.png">
<meta property="og:image" content="http://example.com/2024/03/28/Python%E7%BC%96%E7%A8%8B%E4%BB%8E%E5%85%A5%E9%97%A8%E5%88%B0%E5%AE%9E%E8%B7%B5%E7%BB%83%E4%B9%A0%E9%A2%98/image-20240329165149839.png">
<meta property="og:image" content="http://example.com/2024/03/28/Python%E7%BC%96%E7%A8%8B%E4%BB%8E%E5%85%A5%E9%97%A8%E5%88%B0%E5%AE%9E%E8%B7%B5%E7%BB%83%E4%B9%A0%E9%A2%98/image-20240329172653728.png">
<meta property="article:published_time" content="2024-03-28T10:25:17.000Z">
<meta property="article:modified_time" content="2024-04-08T03:07:19.499Z">
<meta property="article:tag" content="python入门">
<meta property="article:tag" content="python实践">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="http://example.com/2024/03/28/Python%E7%BC%96%E7%A8%8B%E4%BB%8E%E5%85%A5%E9%97%A8%E5%88%B0%E5%AE%9E%E8%B7%B5%E7%BB%83%E4%B9%A0%E9%A2%98/image-20240328192658637.png">
  
  
  
  <title>Python编程从入门到实践练习题 - hgc&#39;s Blog</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/KaTeX/0.16.2/katex.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"example.com","root":"/","version":"1.9.7","typing":{"enable":true,"typeSpeed":90,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":true,"follow_dnt":true,"baidu":"afa27b3408bbab372d2b3aba487978e4","google":{"measurement_id":"G-846D3FPCR6"},"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":"ExOr1FY8NzdDhfdZvDw9D5c2-gzGzoHsz","app_key":"k7IRTVgwpZstqPIhmLpn9lvL","server_url":"https://exor1fy8.lc-cn-n1-shared.com","path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml","include_content_in_search":true};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  

  
    <!-- Baidu Analytics -->
    <script async>
      if (!Fluid.ctx.dnt) {
        var _hmt = _hmt || [];
        (function() {
          var hm = document.createElement("script");
          hm.src = "https://hm.baidu.com/hm.js?afa27b3408bbab372d2b3aba487978e4";
          var s = document.getElementsByTagName("script")[0];
          s.parentNode.insertBefore(hm, s);
        })();
      }
    </script>
  

  
    <!-- Google tag (gtag.js) -->
    <script async>
      if (!Fluid.ctx.dnt) {
        Fluid.utils.createScript("https://www.googletagmanager.com/gtag/js?id=G-846D3FPCR6", function() {
          window.dataLayer = window.dataLayer || [];
          function gtag() {
            dataLayer.push(arguments);
          }
          gtag('js', new Date());
          gtag('config', 'G-846D3FPCR6');
        });
      }
    </script>
  

  

  

  

  
    
  



  
<meta name="generator" content="Hexo 7.1.1"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>hgcheng&#39;s blog</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/" target="_self">
                <i class="iconfont icon-home-fill"></i>
                <span>首页</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/" target="_self">
                <i class="iconfont icon-archive-fill"></i>
                <span>归档</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/" target="_self">
                <i class="iconfont icon-category-fill"></i>
                <span>分类</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/" target="_self">
                <i class="iconfont icon-tags-fill"></i>
                <span>标签</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/" target="_self">
                <i class="iconfont icon-user-fill"></i>
                <span>关于</span>
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              <i class="iconfont icon-search"></i>
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">
              <i class="iconfont icon-dark" id="color-toggle-icon"></i>
            </a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/banner1.jpg') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="Python编程从入门到实践练习题"></span>
          
        </div>

        
          
  <div class="mt-3">
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2024-03-28 18:25" pubdate>
          2024年3月28日 晚上
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          2.5k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          21 分钟
        
      </span>
    

    
    
      
        <span id="leancloud-page-views-container" class="post-meta" style="display: none">
          <i class="iconfont icon-eye" aria-hidden="true"></i>
          <span id="leancloud-page-views"></span> 次
        </span>
        
      
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <h1 id="seo-header">Python编程从入门到实践练习题</h1>
            
              <p id="updated-time" class="note note-info" style="display: none">
                
                  
                    本文最后更新于 2024-04-08T11:07:19+08:00
                  
                  

                
              </p>
            
            
              <div class="markdown-body">
                
                <h1>前言</h1>
<p>本篇是《 Python编程从入门到实践 》一书的练习部分的代码</p>
<p>花费了些许时间，将这本书非项目实践部分看了一遍，因为有其他语言的基础，所以看起来相对来说不是很费劲。纸上得来终觉浅，觉知此事要躬行！加油！</p>
<h2 id="第二章">第二章</h2>
<h3 id="练习2-1">练习2.1</h3>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs python">val = <span class="hljs-string">&quot;hello world&quot;</span><br><span class="hljs-built_in">print</span>(val)<br></code></pre></td></tr></table></figure>
<img src="/2024/03/28/Python%E7%BC%96%E7%A8%8B%E4%BB%8E%E5%85%A5%E9%97%A8%E5%88%B0%E5%AE%9E%E8%B7%B5%E7%BB%83%E4%B9%A0%E9%A2%98/image-20240328192658637.png" srcset="/img/loading.gif" lazyload class="" title="image-20240328192658637">
<h3 id="练习2-2">练习2.2</h3>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs python">val = <span class="hljs-string">&quot;hello world&quot;</span><br><span class="hljs-built_in">print</span>(val)<br>val = <span class="hljs-string">&quot;new hello world&quot;</span><br><span class="hljs-built_in">print</span>(val)<br></code></pre></td></tr></table></figure>
<img src="/2024/03/28/Python%E7%BC%96%E7%A8%8B%E4%BB%8E%E5%85%A5%E9%97%A8%E5%88%B0%E5%AE%9E%E8%B7%B5%E7%BB%83%E4%B9%A0%E9%A2%98/image-20240328192831111.png" srcset="/img/loading.gif" lazyload class="" title="image-20240328192831111">
<h3 id="练习2-3">练习2.3</h3>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs python">name = <span class="hljs-string">&quot;tom&quot;</span><br><span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;hello <span class="hljs-subst">&#123;name&#125;</span>,do you like the orange?&quot;</span>)<br></code></pre></td></tr></table></figure>
<img src="/2024/03/28/Python%E7%BC%96%E7%A8%8B%E4%BB%8E%E5%85%A5%E9%97%A8%E5%88%B0%E5%AE%9E%E8%B7%B5%E7%BB%83%E4%B9%A0%E9%A2%98/image-20240328193043760.png" srcset="/img/loading.gif" lazyload class="" title="image-20240328193043760">
<h3 id="练习2-4">练习2.4</h3>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs python">name = <span class="hljs-string">&quot;tom&quot;</span><br><span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;hello <span class="hljs-subst">&#123;name&#125;</span>,do you like the orange?&quot;</span>)<br><span class="hljs-built_in">print</span>(name.lower())<br><span class="hljs-built_in">print</span>(name.upper())<br><span class="hljs-built_in">print</span>(name.title())<br></code></pre></td></tr></table></figure>
<img src="/2024/03/28/Python%E7%BC%96%E7%A8%8B%E4%BB%8E%E5%85%A5%E9%97%A8%E5%88%B0%E5%AE%9E%E8%B7%B5%E7%BB%83%E4%B9%A0%E9%A2%98/image-20240328193211082.png" srcset="/img/loading.gif" lazyload class="" title="image-20240328193211082">
<h3 id="练习2-5">练习2.5</h3>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs python">s1 = <span class="hljs-string">&quot;I say:\&quot;There is a will,there is a way.\&quot;&quot;</span><br><span class="hljs-built_in">print</span>(s1)<br></code></pre></td></tr></table></figure>
<img src="/2024/03/28/Python%E7%BC%96%E7%A8%8B%E4%BB%8E%E5%85%A5%E9%97%A8%E5%88%B0%E5%AE%9E%E8%B7%B5%E7%BB%83%E4%B9%A0%E9%A2%98/image-20240328193644393.png" srcset="/img/loading.gif" lazyload class="" title="image-20240328193644393">
<h3 id="练习2-6">练习2.6</h3>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs python">s1 = <span class="hljs-string">&quot;I say:\&quot;There is a will,there is a way.\&quot;&quot;</span><br><span class="hljs-built_in">print</span>(s1)<br><br>person_name = <span class="hljs-string">&quot;tom&quot;</span><br>message = <span class="hljs-string">f&quot;<span class="hljs-subst">&#123;person_name.title()&#125;</span> say:\&quot;There is a will,there is a way.\&quot;&quot;</span><br><span class="hljs-built_in">print</span>(message)<br></code></pre></td></tr></table></figure>
<img src="/2024/03/28/Python%E7%BC%96%E7%A8%8B%E4%BB%8E%E5%85%A5%E9%97%A8%E5%88%B0%E5%AE%9E%E8%B7%B5%E7%BB%83%E4%B9%A0%E9%A2%98/image-20240328193844302.png" srcset="/img/loading.gif" lazyload class="" title="image-20240328193844302">
<h3 id="练习2-7">练习2.7</h3>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs python">name = <span class="hljs-string">&quot;\t\tJacket cheng\n\t\n&quot;</span><br><span class="hljs-built_in">print</span>(name.strip())<br></code></pre></td></tr></table></figure>
<img src="/2024/03/28/Python%E7%BC%96%E7%A8%8B%E4%BB%8E%E5%85%A5%E9%97%A8%E5%88%B0%E5%AE%9E%E8%B7%B5%E7%BB%83%E4%B9%A0%E9%A2%98/image-20240328194620513.png" srcset="/img/loading.gif" lazyload class="" title="image-20240328194620513">
<h3 id="练习2-8">练习2.8</h3>
<p>去除字符串前缀 <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>s</mi><mi>t</mi><mi>r</mi><mi mathvariant="normal">.</mi><mi>r</mi><mi>e</mi><mi>m</mi><mi>o</mi><mi>v</mi><mi>e</mi><mi>p</mi><mi>r</mi><mi>e</mi><mi>f</mi><mi>i</mi><mi>x</mi><msup><mo stretchy="false">(</mo><mo mathvariant="normal" lspace="0em" rspace="0em">′</mo></msup><mi>x</mi><mi>x</mi><msup><mi>x</mi><mo mathvariant="normal" lspace="0em" rspace="0em">′</mo></msup><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">str.removeprefix(&#x27;xxx&#x27;)</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1.0019em;vertical-align:-0.25em;"></span><span class="mord mathnormal">s</span><span class="mord mathnormal">t</span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mord">.</span><span class="mord mathnormal">re</span><span class="mord mathnormal">m</span><span class="mord mathnormal">o</span><span class="mord mathnormal" style="margin-right:0.03588em;">v</span><span class="mord mathnormal">e</span><span class="mord mathnormal">p</span><span class="mord mathnormal">re</span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal">i</span><span class="mord mathnormal">x</span><span class="mopen"><span class="mopen">(</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.7519em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">′</span></span></span></span></span></span></span></span></span><span class="mord mathnormal">xx</span><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.7519em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">′</span></span></span></span></span></span></span></span></span><span class="mclose">)</span></span></span></span></p>
<p>去除字符串后缀 <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>s</mi><mi>t</mi><mi>r</mi><mi mathvariant="normal">.</mi><mi>r</mi><mi>e</mi><mi>m</mi><mi>o</mi><mi>v</mi><mi>e</mi><mi>s</mi><mi>u</mi><mi>f</mi><mi>f</mi><mi>i</mi><mi>x</mi><msup><mo stretchy="false">(</mo><mo mathvariant="normal" lspace="0em" rspace="0em">′</mo></msup><mi>x</mi><mi>x</mi><msup><mi>x</mi><mo mathvariant="normal" lspace="0em" rspace="0em">′</mo></msup><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">str.removesuffix(&#x27;xxx&#x27;)</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1.0019em;vertical-align:-0.25em;"></span><span class="mord mathnormal">s</span><span class="mord mathnormal">t</span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mord">.</span><span class="mord mathnormal">re</span><span class="mord mathnormal">m</span><span class="mord mathnormal">o</span><span class="mord mathnormal" style="margin-right:0.03588em;">v</span><span class="mord mathnormal">es</span><span class="mord mathnormal">u</span><span class="mord mathnormal" style="margin-right:0.10764em;">ff</span><span class="mord mathnormal">i</span><span class="mord mathnormal">x</span><span class="mopen"><span class="mopen">(</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.7519em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">′</span></span></span></span></span></span></span></span></span><span class="mord mathnormal">xx</span><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.7519em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">′</span></span></span></span></span></span></span></span></span><span class="mclose">)</span></span></span></span></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs python">name = <span class="hljs-string">&quot;https://baidu.com&quot;</span><br><span class="hljs-built_in">print</span>(name.removeprefix(<span class="hljs-string">&quot;https://&quot;</span>))<br>file_name = <span class="hljs-string">&quot;test.json&quot;</span><br><span class="hljs-built_in">print</span>(file_name.removesuffix(<span class="hljs-string">&quot;.json&quot;</span>))<br></code></pre></td></tr></table></figure>
<img src="/2024/03/28/Python%E7%BC%96%E7%A8%8B%E4%BB%8E%E5%85%A5%E9%97%A8%E5%88%B0%E5%AE%9E%E8%B7%B5%E7%BB%83%E4%B9%A0%E9%A2%98/image-20240329105146608.png" srcset="/img/loading.gif" lazyload class="" title="image-20240329105146608">
<h3 id="练习2-9">练习2.9</h3>
<ul>
<li>将两个数相除，结果总是浮点数( 即便这两个数是整数，例如 16 / 2 = 8.0 )</li>
<li>只要有操作数是浮点数，那么结果就是浮点数</li>
<li>* * 表示乘方运算 <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>3</mn><mo>∗</mo><mo>∗</mo><mn>2</mn><mo>=</mo><msup><mn>3</mn><mn>2</mn></msup><mo>=</mo><mn>9</mn></mrow><annotation encoding="application/x-tex">3**2=3^2=9</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6444em;"></span><span class="mord">3</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">∗</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:0.6444em;"></span><span class="mord">∗</span><span class="mord">2</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.8141em;"></span><span class="mord"><span class="mord">3</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8141em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.6444em;"></span><span class="mord">9</span></span></span></span></li>
</ul>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-built_in">print</span>(<span class="hljs-number">5</span> + <span class="hljs-number">3</span>)<br><span class="hljs-built_in">print</span>(<span class="hljs-number">9</span> - <span class="hljs-number">1</span>)<br><span class="hljs-built_in">print</span>(<span class="hljs-number">2</span> * <span class="hljs-number">4</span>)<br><span class="hljs-built_in">print</span>(<span class="hljs-number">16</span> / <span class="hljs-number">2</span>)<br></code></pre></td></tr></table></figure>
<img src="/2024/03/28/Python%E7%BC%96%E7%A8%8B%E4%BB%8E%E5%85%A5%E9%97%A8%E5%88%B0%E5%AE%9E%E8%B7%B5%E7%BB%83%E4%B9%A0%E9%A2%98/image-20240329155329532.png" srcset="/img/loading.gif" lazyload class="" title="image-20240329155329532">
<h3 id="练习2-10">练习2.10</h3>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs python">favorite_num = <span class="hljs-number">1</span><br>message = <span class="hljs-string">f&quot;my favorite num is <span class="hljs-subst">&#123;favorite_num&#125;</span>&quot;</span><br><span class="hljs-built_in">print</span>(message)<br></code></pre></td></tr></table></figure>
<img src="/2024/03/28/Python%E7%BC%96%E7%A8%8B%E4%BB%8E%E5%85%A5%E9%97%A8%E5%88%B0%E5%AE%9E%E8%B7%B5%E7%BB%83%E4%B9%A0%E9%A2%98/image-20240329163439454.png" srcset="/img/loading.gif" lazyload class="" title="image-20240329163439454">
<h2 id="第三章">第三章</h2>
<h3 id="练习3-1">练习3.1</h3>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs python">names = [<span class="hljs-string">&quot;tom&quot;</span>, <span class="hljs-string">&quot;niuniu&quot;</span>, <span class="hljs-string">&quot;bei ta&quot;</span>]<br><span class="hljs-keyword">for</span> name <span class="hljs-keyword">in</span> names:<br>    <span class="hljs-built_in">print</span>(name)<br></code></pre></td></tr></table></figure>
<img src="/2024/03/28/Python%E7%BC%96%E7%A8%8B%E4%BB%8E%E5%85%A5%E9%97%A8%E5%88%B0%E5%AE%9E%E8%B7%B5%E7%BB%83%E4%B9%A0%E9%A2%98/image-20240329163951830.png" srcset="/img/loading.gif" lazyload class="" title="image-20240329163951830">
<h3 id="练习3-2">练习3.2</h3>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs python">names = [<span class="hljs-string">&quot;tom&quot;</span>, <span class="hljs-string">&quot;niuniu&quot;</span>, <span class="hljs-string">&quot;bei ta&quot;</span>]<br><span class="hljs-keyword">for</span> name <span class="hljs-keyword">in</span> names:<br>    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;<span class="hljs-subst">&#123;name&#125;</span>,nice to meet you！&quot;</span>)<br></code></pre></td></tr></table></figure>
<img src="/2024/03/28/Python%E7%BC%96%E7%A8%8B%E4%BB%8E%E5%85%A5%E9%97%A8%E5%88%B0%E5%AE%9E%E8%B7%B5%E7%BB%83%E4%B9%A0%E9%A2%98/image-20240329165149839.png" srcset="/img/loading.gif" lazyload class="" title="image-20240329165149839">
<h3 id="练习3-4、3-5、3-6、3-7">练习3.4、3.5、3.6、3.7</h3>
<ul>
<li>
<p><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>l</mi><mi>i</mi><mi>s</mi><mi>t</mi><mi mathvariant="normal">.</mi><mi>a</mi><mi>p</mi><mi>p</mi><mi>e</mi><mi>n</mi><mi>d</mi><mo stretchy="false">(</mo><mi>e</mi><mi>l</mi><mi>e</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">list.append(ele)</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">i</span><span class="mord mathnormal">s</span><span class="mord mathnormal">t</span><span class="mord">.</span><span class="mord mathnormal">a</span><span class="mord mathnormal">pp</span><span class="mord mathnormal">e</span><span class="mord mathnormal">n</span><span class="mord mathnormal">d</span><span class="mopen">(</span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">e</span><span class="mclose">)</span></span></span></span> 是追加元素，在列表的最后加元素</p>
</li>
<li>
<p><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>l</mi><mi>i</mi><mi>s</mi><mi>t</mi><mi mathvariant="normal">.</mi><mi>i</mi><mi>n</mi><mi>s</mi><mi>e</mi><mi>r</mi><mi>t</mi><mo stretchy="false">(</mo><mi>i</mi><mi>n</mi><mi>d</mi><mi>e</mi><mi>x</mi><mo separator="true">,</mo><mi>e</mi><mi>l</mi><mi>e</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">list.insert(index,ele)</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">i</span><span class="mord mathnormal">s</span><span class="mord mathnormal">t</span><span class="mord">.</span><span class="mord mathnormal">in</span><span class="mord mathnormal" style="margin-right:0.02778em;">ser</span><span class="mord mathnormal">t</span><span class="mopen">(</span><span class="mord mathnormal">in</span><span class="mord mathnormal">d</span><span class="mord mathnormal">e</span><span class="mord mathnormal">x</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">e</span><span class="mclose">)</span></span></span></span>  在指定索引位置处插入元素</p>
</li>
<li>
<p><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>d</mi><mi>e</mi><mi>l</mi><mtext>   </mtext><mi>l</mi><mi>i</mi><mi>s</mi><mi>t</mi><mo stretchy="false">[</mo><mi>i</mi><mi>n</mi><mi>d</mi><mi>e</mi><mi>x</mi><mo stretchy="false">]</mo></mrow><annotation encoding="application/x-tex">del \ \ \  list[index]</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">d</span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mspace"> </span><span class="mspace"> </span><span class="mspace"> </span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">i</span><span class="mord mathnormal">s</span><span class="mord mathnormal">t</span><span class="mopen">[</span><span class="mord mathnormal">in</span><span class="mord mathnormal">d</span><span class="mord mathnormal">e</span><span class="mord mathnormal">x</span><span class="mclose">]</span></span></span></span>  如果不需要用到删除的元素，且已知要删的元素的位置，可使用 <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>d</mi><mi>e</mi><mi>l</mi></mrow><annotation encoding="application/x-tex">del</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6944em;"></span><span class="mord mathnormal">d</span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span></span></span></span></p>
<p>删除之后，就无法再访问它了；删除0位置的元素，整体元素向左移动了一位</p>
</li>
<li>
<p><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>l</mi><mi>i</mi><mi>s</mi><mi>t</mi><mi mathvariant="normal">.</mi><mi>r</mi><mi>e</mi><mi>m</mi><mi>o</mi><mi>v</mi><mi>e</mi><mo stretchy="false">(</mo><mi>e</mi><mi>l</mi><mi>e</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">list.remove(ele)</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">i</span><span class="mord mathnormal">s</span><span class="mord mathnormal">t</span><span class="mord">.</span><span class="mord mathnormal">re</span><span class="mord mathnormal">m</span><span class="mord mathnormal">o</span><span class="mord mathnormal" style="margin-right:0.03588em;">v</span><span class="mord mathnormal">e</span><span class="mopen">(</span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">e</span><span class="mclose">)</span></span></span></span>      删除指定的元素【但是只删除第一个出现的  <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>e</mi><mi>l</mi><mi>e</mi></mrow><annotation encoding="application/x-tex">ele</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6944em;"></span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">e</span></span></span></span>  】</p>
</li>
<li>
<p><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>e</mi><mi>l</mi><mi>e</mi><mo>=</mo><mi>l</mi><mi>i</mi><mi>s</mi><mi>t</mi><mi mathvariant="normal">.</mi><mi>p</mi><mi>o</mi><mi>p</mi><mo stretchy="false">(</mo><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">ele=list.pop()</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6944em;"></span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">e</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">i</span><span class="mord mathnormal">s</span><span class="mord mathnormal">t</span><span class="mord">.</span><span class="mord mathnormal">p</span><span class="mord mathnormal">o</span><span class="mord mathnormal">p</span><span class="mopen">(</span><span class="mclose">)</span></span></span></span>   弹出列表的末尾元素 并接收</p>
</li>
<li>
<p><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>e</mi><mi>l</mi><mi>e</mi><mo>=</mo><mi>l</mi><mi>i</mi><mi>s</mi><mi>t</mi><mi mathvariant="normal">.</mi><mi>p</mi><mi>o</mi><mi>p</mi><mo stretchy="false">(</mo><mi>i</mi><mi>n</mi><mi>d</mi><mi>e</mi><mi>x</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">ele=list.pop(index)</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6944em;"></span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">e</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">i</span><span class="mord mathnormal">s</span><span class="mord mathnormal">t</span><span class="mord">.</span><span class="mord mathnormal">p</span><span class="mord mathnormal">o</span><span class="mord mathnormal">p</span><span class="mopen">(</span><span class="mord mathnormal">in</span><span class="mord mathnormal">d</span><span class="mord mathnormal">e</span><span class="mord mathnormal">x</span><span class="mclose">)</span></span></span></span>  弹出指定位置的元素 并接收</p>
</li>
<li>
<p><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>p</mi><mi>o</mi><mi>p</mi><mtext>、</mtext><mi>d</mi><mi>e</mi><mi>l</mi><mtext>、</mtext><mi>r</mi><mi>e</mi><mi>m</mi><mi>o</mi><mi>v</mi><mi>e</mi></mrow><annotation encoding="application/x-tex">pop、del、remove</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal">p</span><span class="mord mathnormal">o</span><span class="mord mathnormal">p</span><span class="mord cjk_fallback">、</span><span class="mord mathnormal">d</span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord cjk_fallback">、</span><span class="mord mathnormal">re</span><span class="mord mathnormal">m</span><span class="mord mathnormal">o</span><span class="mord mathnormal" style="margin-right:0.03588em;">v</span><span class="mord mathnormal">e</span></span></span></span>  之后，列表中将不再有这些元素</p>
</li>
</ul>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><code class="hljs python">names = [<span class="hljs-string">&quot;hgc&quot;</span>, <span class="hljs-string">&quot;tom&quot;</span>, <span class="hljs-string">&quot;jack&quot;</span>, <span class="hljs-string">&quot;bei ta&quot;</span>]<br><span class="hljs-keyword">for</span> name <span class="hljs-keyword">in</span> names:<br>    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;<span class="hljs-subst">&#123;name&#125;</span>,welcome to this party!&quot;</span>)<br><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;================================&quot;</span>)<br><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;bei ta doesn&#x27;t participate in the party&quot;</span>)<br>names[<span class="hljs-number">3</span>] = <span class="hljs-string">&quot;shu ke&quot;</span><br><span class="hljs-keyword">for</span> name <span class="hljs-keyword">in</span> names:<br>    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;<span class="hljs-subst">&#123;name&#125;</span>,welcome to this party!&quot;</span>)<br><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;=============we find a bigger desk!===================&quot;</span>)<br>names.insert(<span class="hljs-number">0</span>, <span class="hljs-string">&quot;ao ba ma&quot;</span>)<br>names.insert(<span class="hljs-built_in">int</span>(<span class="hljs-built_in">len</span>(names) / <span class="hljs-number">2</span> + <span class="hljs-number">1</span>), <span class="hljs-string">&quot;ze li&quot;</span>)<br>names.append(<span class="hljs-string">&quot;join&quot;</span>)<br><span class="hljs-keyword">for</span> name <span class="hljs-keyword">in</span> names:<br>    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;<span class="hljs-subst">&#123;name&#125;</span>,welcome to this party!&quot;</span>)<br><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;==============we only invite 2 customer!==============&quot;</span>)<br><span class="hljs-keyword">while</span> <span class="hljs-built_in">len</span>(names) != <span class="hljs-number">2</span>:<br>    name = names.pop()<br>    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;sorry,<span class="hljs-subst">&#123;name&#125;</span>,you should go home!&quot;</span>)<br><br><span class="hljs-keyword">for</span> name <span class="hljs-keyword">in</span> names:<br>    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;<span class="hljs-subst">&#123;name&#125;</span>,you can com to our party!&quot;</span>)<br><br><span class="hljs-keyword">del</span> names[<span class="hljs-number">0</span>]<br><span class="hljs-keyword">del</span> names[<span class="hljs-number">0</span>]<br><span class="hljs-built_in">print</span>(names)<br></code></pre></td></tr></table></figure>
<img src="/2024/03/28/Python%E7%BC%96%E7%A8%8B%E4%BB%8E%E5%85%A5%E9%97%A8%E5%88%B0%E5%AE%9E%E8%B7%B5%E7%BB%83%E4%B9%A0%E9%A2%98/image-20240329172653728.png" srcset="/img/loading.gif" lazyload class="" title="image-20240329172653728">
<h3 id="练习3-8">练习3.8</h3>
<ul>
<li><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>s</mi><mi>o</mi><mi>r</mi><mi>t</mi><mi>e</mi><mi>d</mi><mo stretchy="false">(</mo><mi>l</mi><mi>i</mi><mi>s</mi><mi>t</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">sorted(list)</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.02778em;">sor</span><span class="mord mathnormal">t</span><span class="mord mathnormal">e</span><span class="mord mathnormal">d</span><span class="mopen">(</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">i</span><span class="mord mathnormal">s</span><span class="mord mathnormal">t</span><span class="mclose">)</span></span></span></span>   不改变原列表元素，返回一个顺序排序的新列表 ( 按照ABC . . . a. b. c )</li>
<li><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>s</mi><mi>o</mi><mi>r</mi><mi>t</mi><mi>e</mi><mi>d</mi><mo stretchy="false">(</mo><mi>l</mi><mi>i</mi><mi>s</mi><mi>t</mi><mo separator="true">,</mo><mi>r</mi><mi>e</mi><mi>v</mi><mi>e</mi><mi>r</mi><mi>s</mi><mi>e</mi><mo>=</mo><mi>T</mi><mi>r</mi><mi>u</mi><mi>e</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">sorted(list,reverse=True)</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.02778em;">sor</span><span class="mord mathnormal">t</span><span class="mord mathnormal">e</span><span class="mord mathnormal">d</span><span class="mopen">(</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">i</span><span class="mord mathnormal">s</span><span class="mord mathnormal">t</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathnormal">re</span><span class="mord mathnormal" style="margin-right:0.03588em;">v</span><span class="mord mathnormal">erse</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.13889em;">T</span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mord mathnormal">u</span><span class="mord mathnormal">e</span><span class="mclose">)</span></span></span></span>   不改变原列表元素，返回一个顺序排序的新列表（ 按照相反的顺序 ）</li>
<li><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>l</mi><mi>i</mi><mi>s</mi><mi>t</mi><mi mathvariant="normal">.</mi><mi>s</mi><mi>o</mi><mi>r</mi><mi>t</mi><mo stretchy="false">(</mo><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">list.sort()</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">i</span><span class="mord mathnormal">s</span><span class="mord mathnormal">t</span><span class="mord">.</span><span class="mord mathnormal" style="margin-right:0.02778em;">sor</span><span class="mord mathnormal">t</span><span class="mopen">(</span><span class="mclose">)</span></span></span></span>  改变原列表元素 ，顺序排序</li>
<li><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>l</mi><mi>i</mi><mi>s</mi><mi>t</mi><mi mathvariant="normal">.</mi><mi>s</mi><mi>o</mi><mi>r</mi><mi>t</mi><mo stretchy="false">(</mo><mi>r</mi><mi>e</mi><mi>v</mi><mi>e</mi><mi>r</mi><mi>s</mi><mi>e</mi><mo>=</mo><mi>T</mi><mi>r</mi><mi>u</mi><mi>e</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">list.sort(reverse=True)</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">i</span><span class="mord mathnormal">s</span><span class="mord mathnormal">t</span><span class="mord">.</span><span class="mord mathnormal" style="margin-right:0.02778em;">sor</span><span class="mord mathnormal">t</span><span class="mopen">(</span><span class="mord mathnormal">re</span><span class="mord mathnormal" style="margin-right:0.03588em;">v</span><span class="mord mathnormal">erse</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.13889em;">T</span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mord mathnormal">u</span><span class="mord mathnormal">e</span><span class="mclose">)</span></span></span></span>  改变原列表元素 ，反序排序</li>
<li><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>l</mi><mi>i</mi><mi>s</mi><mi>t</mi><mi mathvariant="normal">.</mi><mi>r</mi><mi>e</mi><mi>v</mi><mi>e</mi><mi>r</mi><mi>s</mi><mi>e</mi></mrow><annotation encoding="application/x-tex">list.reverse</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6944em;"></span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">i</span><span class="mord mathnormal">s</span><span class="mord mathnormal">t</span><span class="mord">.</span><span class="mord mathnormal">re</span><span class="mord mathnormal" style="margin-right:0.03588em;">v</span><span class="mord mathnormal">erse</span></span></span></span>  改变原列表，将列表翻转</li>
<li>列表.方法  会改变原列表 ；方法(列表)  不改变原列表，产生新的列表</li>
</ul>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><code class="hljs python">place = [<span class="hljs-string">&quot;beijing&quot;</span>, <span class="hljs-string">&quot;shanghai&quot;</span>, <span class="hljs-string">&quot;US&quot;</span>, <span class="hljs-string">&quot;paris&quot;</span>, <span class="hljs-string">&quot;jiang su&quot;</span>]<br><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;====== print place&quot;</span>)<br><span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> place:<br>    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;- <span class="hljs-subst">&#123;i&#125;</span>&quot;</span>)<br><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;========sorted&quot;</span>)<br>tmp_ls = <span class="hljs-built_in">sorted</span>(place)<br><span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> tmp_ls:<br>    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;- <span class="hljs-subst">&#123;i&#125;</span>&quot;</span>)<br><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;======check origin ls&quot;</span>)<br><span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> place:<br>    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;- <span class="hljs-subst">&#123;i&#125;</span>&quot;</span>)<br><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;======sorted reverse&quot;</span>)<br>tmp_ls_reverse = <span class="hljs-built_in">sorted</span>(place, reverse=<span class="hljs-literal">True</span>)<br><span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> tmp_ls_reverse:<br>    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;- <span class="hljs-subst">&#123;i&#125;</span>&quot;</span>)<br><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;=======check origin ls&quot;</span>)<br><span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> place:<br>    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;- <span class="hljs-subst">&#123;i&#125;</span>&quot;</span>)<br><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;==========reverse ls&quot;</span>)<br>place.reverse()<br><span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> place:<br>    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;- <span class="hljs-subst">&#123;i&#125;</span>&quot;</span>)<br><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;==========reverse ls and reverse again&quot;</span>)<br>place.reverse()<br><span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> place:<br>    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;- <span class="hljs-subst">&#123;i&#125;</span>&quot;</span>)<br><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;========= sort the ls&quot;</span>)<br>place.sort()<br><span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> place:<br>    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;- <span class="hljs-subst">&#123;i&#125;</span>&quot;</span>)<br><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;======= sort and reverse the is&quot;</span>)<br>place.sort(reverse=<span class="hljs-literal">True</span>)<br><span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> place:<br>    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;- <span class="hljs-subst">&#123;i&#125;</span>&quot;</span>)<br></code></pre></td></tr></table></figure>
<h2 id="第四章">第四章</h2>
<h3 id="练习4-1">练习4.1</h3>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs python">pi_sa = [<span class="hljs-string">&quot;pisa1&quot;</span>, <span class="hljs-string">&quot;pisa2&quot;</span>, <span class="hljs-string">&quot;pisa3&quot;</span>]<br><span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> pi_sa:<br>    <span class="hljs-built_in">print</span>(i)<br><span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> pi_sa:<br>    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;I like <span class="hljs-subst">&#123;i&#125;</span>&quot;</span>)<br><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;I really like pisa!&quot;</span>)<br></code></pre></td></tr></table></figure>
<h3 id="练习4-2">练习4.2</h3>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs python">pets = [<span class="hljs-string">&quot;dog&quot;</span>, <span class="hljs-string">&quot;cat&quot;</span>, <span class="hljs-string">&quot;duck&quot;</span>]<br><span class="hljs-keyword">for</span> pet <span class="hljs-keyword">in</span> pets:<br>    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;A <span class="hljs-subst">&#123;pet&#125;</span> would make a great pet.&quot;</span>)<br><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Any of these animals would make a great pet!&quot;</span>)<br></code></pre></td></tr></table></figure>
<h3 id="练习4-3">练习4.3</h3>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">1</span>, <span class="hljs-number">21</span>):<br>    <span class="hljs-built_in">print</span>(i)<br></code></pre></td></tr></table></figure>
<h3 id="练习4-4">练习4.4</h3>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs python">ls = [i <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">1</span>, <span class="hljs-number">1000001</span>)]<br><span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> ls:<br>    <span class="hljs-built_in">print</span>(i)<br></code></pre></td></tr></table></figure>
<h3 id="练习4-5">练习4.5</h3>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs python">ls = [i <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">1</span>, <span class="hljs-number">1000001</span>)]<br><span class="hljs-built_in">print</span>(<span class="hljs-built_in">min</span>(ls))<br><span class="hljs-built_in">print</span>(<span class="hljs-built_in">max</span>(ls))<br><span class="hljs-built_in">print</span>(<span class="hljs-built_in">sum</span>(ls))<br></code></pre></td></tr></table></figure>
<h3 id="练习4-6">练习4.6</h3>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs python">ls = [i <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">1</span>, <span class="hljs-number">21</span>, <span class="hljs-number">2</span>)]<br><span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> ls:<br>    <span class="hljs-built_in">print</span>(i)<br></code></pre></td></tr></table></figure>
<h3 id="练习4-7">练习4.7</h3>
<ul>
<li>列表推导式，最前面的 <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>i</mi></mrow><annotation encoding="application/x-tex">i</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6595em;"></span><span class="mord mathnormal">i</span></span></span></span> 表达式是最终的结果，如果要加筛选条件，就加在for循环的后面，用<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>i</mi><mi>f</mi></mrow><annotation encoding="application/x-tex">if</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal">i</span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span></span></span></span></li>
</ul>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs python">ls = [i <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">3</span>, <span class="hljs-number">31</span>) <span class="hljs-keyword">if</span> i % <span class="hljs-number">3</span> == <span class="hljs-number">0</span>]<br><span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> ls:<br>    <span class="hljs-built_in">print</span>(i)<br></code></pre></td></tr></table></figure>
<h3 id="练习4-8">练习4.8</h3>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs python">ls = [i ** <span class="hljs-number">3</span> <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">1</span>, <span class="hljs-number">11</span>)]<br><span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> ls:<br>    <span class="hljs-built_in">print</span>(i)<br></code></pre></td></tr></table></figure>
<h3 id="练习4-10">练习4.10</h3>
<ul>
<li>
<p>列表的索引 <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo stretchy="false">[</mo><mi>m</mi><mo separator="true">,</mo><mi>n</mi><mo stretchy="false">]</mo></mrow><annotation encoding="application/x-tex">[m,n]</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">[</span><span class="mord mathnormal">m</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathnormal">n</span><span class="mclose">]</span></span></span></span> 是左闭右开，不包含右边界索引，如同 <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>r</mi><mi>a</mi><mi>n</mi><mi>g</mi><mi>e</mi><mo stretchy="false">(</mo><mi>m</mi><mo separator="true">,</mo><mi>n</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">range(m,n)</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mord mathnormal">an</span><span class="mord mathnormal" style="margin-right:0.03588em;">g</span><span class="mord mathnormal">e</span><span class="mopen">(</span><span class="mord mathnormal">m</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathnormal">n</span><span class="mclose">)</span></span></span></span> 一样，不包含右边界</p>
</li>
<li>
<p><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>l</mi><mi>s</mi><mo stretchy="false">[</mo><mo>:</mo><mo stretchy="false">]</mo></mrow><annotation encoding="application/x-tex">ls[:]</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">s</span><span class="mopen">[</span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mclose">]</span></span></span></span> 从头取到尾</p>
</li>
<li>
<p><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>l</mi><mi>s</mi><mo stretchy="false">[</mo><mo>:</mo><mi>n</mi><mo stretchy="false">]</mo></mrow><annotation encoding="application/x-tex">ls[:n]</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">s</span><span class="mopen">[</span><span class="mrel">:</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">n</span><span class="mclose">]</span></span></span></span> 从头取到第 <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>n</mi></mrow><annotation encoding="application/x-tex">n</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.4306em;"></span><span class="mord mathnormal">n</span></span></span></span> 个元素</p>
</li>
<li>
<p><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>l</mi><mi>s</mi><mo stretchy="false">[</mo><mn>3</mn><mo>:</mo><mo stretchy="false">]</mo></mrow><annotation encoding="application/x-tex">ls[3:]</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">s</span><span class="mopen">[</span><span class="mord">3</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mclose">]</span></span></span></span>  表示从第四个元素取到底</p>
</li>
</ul>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs python">pi_sa = [<span class="hljs-string">&quot;pisa1&quot;</span>, <span class="hljs-string">&quot;pisa2&quot;</span>, <span class="hljs-string">&quot;pisa3&quot;</span>]<br><br><span class="hljs-built_in">print</span>(pi_sa[-<span class="hljs-number">3</span>:])<br><span class="hljs-built_in">print</span>(pi_sa[<span class="hljs-number">0</span>::<span class="hljs-number">2</span>])<br><span class="hljs-comment"># 负索引代表到边界几个距离，三个参数，start:end:步长   第二个参数没有值 默认从倒数第三个一直撸到底</span><br><span class="hljs-built_in">print</span>(pi_sa[-<span class="hljs-number">3</span>::<span class="hljs-number">2</span>])<br><span class="hljs-comment"># 只有个-3 代表倒数第三个元素</span><br><span class="hljs-built_in">print</span>(pi_sa[-<span class="hljs-number">3</span>])<br><span class="hljs-comment"># 切片 索引格式start:end:步长  start是从左数，start为-3，那end只能是在-3右边的数，比如-1，即代表截取倒数第三个到倒数第一个的片段(不包括右边界)</span><br><span class="hljs-built_in">print</span>(pi_sa[-<span class="hljs-number">3</span>:-<span class="hljs-number">1</span>])<br></code></pre></td></tr></table></figure>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs python">ls = [i ** <span class="hljs-number">3</span> <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">1</span>, <span class="hljs-number">11</span>)]<br><span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> ls:<br>    <span class="hljs-built_in">print</span>(i)<br><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;==== the first three items in the list are:&quot;</span>)<br><span class="hljs-built_in">print</span>(ls[:<span class="hljs-number">3</span>])<br><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;==== the middle three items in the list are:&quot;</span>)<br><span class="hljs-comment"># [3:6] 并不一定说是要包含区间相反 这个是不包含右区间的 跟range一样</span><br><span class="hljs-built_in">print</span>(ls[<span class="hljs-number">3</span>:<span class="hljs-number">6</span>])<br><span class="hljs-built_in">print</span>(ls[-<span class="hljs-number">3</span>:])<br></code></pre></td></tr></table></figure>
<h3 id="练习4-11">练习4.11</h3>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><code class="hljs python">pi_sa = [<span class="hljs-string">&quot;pisa1&quot;</span>, <span class="hljs-string">&quot;pisa2&quot;</span>, <span class="hljs-string">&quot;pisa3&quot;</span>]<br><span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> pi_sa:<br>    <span class="hljs-built_in">print</span>(i)<br><span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> pi_sa:<br>    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;I like <span class="hljs-subst">&#123;i&#125;</span>&quot;</span>)<br><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;I really like pisa!&quot;</span>)<br>friend_pizza = pi_sa[:]<br>pi_sa.append(<span class="hljs-string">&quot;pisa4&quot;</span>)<br>friend_pizza.append(<span class="hljs-string">&quot;pisa5&quot;</span>)<br><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;my pisa are:&quot;</span>)<br><span class="hljs-keyword">for</span> e <span class="hljs-keyword">in</span> pi_sa:<br>    <span class="hljs-built_in">print</span>(e)<br><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;my friend&#x27;s pisa are:&quot;</span>)<br><span class="hljs-keyword">for</span> e <span class="hljs-keyword">in</span> friend_pizza:<br>    <span class="hljs-built_in">print</span>(e)<br></code></pre></td></tr></table></figure>
<h3 id="练习4-12">练习4.12</h3>
<ul>
<li>元组是不可更改的数据类型，被称为不可变的列表</li>
<li>如果需要存储一组在程序的整个生命周期内都不变的值，就可以使用元组</li>
</ul>
<p><code>TypeError: 'tuple' object does not support item assignment</code></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-comment"># 元组：不可更改的数据类型</span><br>foods = (<span class="hljs-string">&quot;apple&quot;</span>, <span class="hljs-string">&quot;milk&quot;</span>, <span class="hljs-string">&quot;orange&quot;</span>, <span class="hljs-string">&quot;juice&quot;</span>, <span class="hljs-string">&quot;mango&quot;</span>)<br><span class="hljs-keyword">for</span> food <span class="hljs-keyword">in</span> foods:<br>    <span class="hljs-built_in">print</span>(food)<br>foods[<span class="hljs-number">0</span>] = <span class="hljs-string">&quot;my apple&quot;</span><br><span class="hljs-built_in">print</span>(foods)<br>new_foods = (<span class="hljs-string">&quot;apple&quot;</span>, <span class="hljs-string">&quot;milk&quot;</span>, <span class="hljs-string">&quot;orange&quot;</span>, <span class="hljs-string">&quot;beef&quot;</span>, <span class="hljs-string">&quot;banana&quot;</span>)<br><span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> new_foods:<br>    <span class="hljs-built_in">print</span>(i)<br></code></pre></td></tr></table></figure>
<h2 id="第五章">第五章</h2>
<h3 id="练习5-2">练习5.2</h3>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;a&quot;</span> == <span class="hljs-string">&quot;b&quot;</span>)<br><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;heHe&quot;</span>.lower() == <span class="hljs-string">&quot;hehe&quot;</span>)<br><span class="hljs-built_in">print</span>(<span class="hljs-number">1</span> == <span class="hljs-number">2</span>)<br><span class="hljs-built_in">print</span>(<span class="hljs-number">1</span> &gt;= <span class="hljs-number">2</span>)<br><span class="hljs-built_in">print</span>(<span class="hljs-number">1</span> &lt;= <span class="hljs-number">2</span>)<br><span class="hljs-built_in">print</span>(<span class="hljs-number">1</span> &lt; <span class="hljs-number">2</span>)<br><span class="hljs-built_in">print</span>(<span class="hljs-number">1</span> &gt; <span class="hljs-number">2</span>)<br><span class="hljs-built_in">print</span>(<span class="hljs-number">1</span> &lt; <span class="hljs-number">2</span> <span class="hljs-keyword">and</span> <span class="hljs-number">3</span> &gt; <span class="hljs-number">4</span>)<br><span class="hljs-built_in">print</span>(<span class="hljs-number">1</span> &lt; <span class="hljs-number">2</span> <span class="hljs-keyword">or</span> <span class="hljs-number">3</span> &gt; <span class="hljs-number">4</span>)<br>ls = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>]<br><span class="hljs-built_in">print</span>(<span class="hljs-number">3</span> <span class="hljs-keyword">in</span> ls)<br><span class="hljs-built_in">print</span>(<span class="hljs-number">3</span> <span class="hljs-keyword">not</span> <span class="hljs-keyword">in</span> ls)<br> <br></code></pre></td></tr></table></figure>
<h3 id="练习5-8">练习5.8</h3>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs python">users = [<span class="hljs-string">&quot;tom&quot;</span>, <span class="hljs-string">&quot;admin&quot;</span>, <span class="hljs-string">&quot;jerry&quot;</span>, <span class="hljs-string">&quot;john&quot;</span>, <span class="hljs-string">&quot;hgc&quot;</span>]<br><span class="hljs-keyword">for</span> user <span class="hljs-keyword">in</span> users:<br>    <span class="hljs-keyword">if</span> user == <span class="hljs-string">&quot;admin&quot;</span>:<br>        <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;hello admin,would you like to see a status report?&quot;</span>)<br>    <span class="hljs-keyword">else</span>:<br>        <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;hello <span class="hljs-subst">&#123;user&#125;</span>,thanks for logging in again&quot;</span>)<br></code></pre></td></tr></table></figure>
<h3 id="练习5-10">练习5.10</h3>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><code class="hljs python">current_users = [<span class="hljs-string">&quot;tom&quot;</span>, <span class="hljs-string">&quot;admin&quot;</span>, <span class="hljs-string">&quot;jerry&quot;</span>, <span class="hljs-string">&quot;john&quot;</span>, <span class="hljs-string">&quot;hgc&quot;</span>]<br>new_users = [<span class="hljs-string">&quot;jerry&quot;</span>, <span class="hljs-string">&quot;john&quot;</span>, <span class="hljs-string">&quot;hgc&quot;</span>, <span class="hljs-string">&quot;he tai ji&quot;</span>, <span class="hljs-string">&quot;shu ke&quot;</span>]<br><span class="hljs-keyword">for</span> user <span class="hljs-keyword">in</span> new_users:<br>    <span class="hljs-keyword">if</span> user.lower() <span class="hljs-keyword">in</span> current_users:<br>        <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;please  input other name&quot;</span>)<br>    <span class="hljs-keyword">else</span>:<br>        <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;current user <span class="hljs-subst">&#123;user&#125;</span> could be used&quot;</span>)<br>        <br></code></pre></td></tr></table></figure>
<h3 id="练习5-11">练习5.11</h3>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs python">num = [i <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">1</span>, <span class="hljs-number">10</span>)]<br><span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> num:<br>    <span class="hljs-keyword">if</span> i == <span class="hljs-number">1</span>:<br>        <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;1st&quot;</span>)<br>    <span class="hljs-keyword">elif</span> i == <span class="hljs-number">2</span>:<br>        <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;2nd&quot;</span>)<br>    <span class="hljs-keyword">elif</span> i == <span class="hljs-number">3</span>:<br>        <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;3rd&quot;</span>)<br>    <span class="hljs-keyword">else</span>:<br>        <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;<span class="hljs-subst">&#123;i&#125;</span>th&quot;</span>)<br></code></pre></td></tr></table></figure>
<h2 id="第六章">第六章</h2>
<ul>
<li>访问字典的值   <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>d</mi><mi>i</mi><mi>c</mi><mo stretchy="false">[</mo><mi>k</mi><mi>e</mi><mi>y</mi><mo stretchy="false">]</mo></mrow><annotation encoding="application/x-tex">dic[key]</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">d</span><span class="mord mathnormal">i</span><span class="mord mathnormal">c</span><span class="mopen">[</span><span class="mord mathnormal" style="margin-right:0.03148em;">k</span><span class="mord mathnormal" style="margin-right:0.03588em;">ey</span><span class="mclose">]</span></span></span></span></li>
<li>删除键值对  <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>d</mi><mi>e</mi><mi>l</mi><mtext> </mtext><mi>d</mi><mi>i</mi><mi>c</mi><mo stretchy="false">[</mo><mi>k</mi><mi>e</mi><mi>y</mi><mo stretchy="false">]</mo></mrow><annotation encoding="application/x-tex">del \ dic[key]</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">d</span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mspace"> </span><span class="mord mathnormal">d</span><span class="mord mathnormal">i</span><span class="mord mathnormal">c</span><span class="mopen">[</span><span class="mord mathnormal" style="margin-right:0.03148em;">k</span><span class="mord mathnormal" style="margin-right:0.03588em;">ey</span><span class="mclose">]</span></span></span></span></li>
<li>如果指定的键可能不存在则可以使用  <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>d</mi><mi>i</mi><mi>c</mi><mi mathvariant="normal">.</mi><mi>g</mi><mi>e</mi><mi>t</mi><mo stretchy="false">(</mo><mi>k</mi><mi>e</mi><mi>y</mi><mo separator="true">,</mo><mi>s</mi><mi>t</mi><mi>r</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">dic.get(key,str)</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">d</span><span class="mord mathnormal">i</span><span class="mord mathnormal">c</span><span class="mord">.</span><span class="mord mathnormal" style="margin-right:0.03588em;">g</span><span class="mord mathnormal">e</span><span class="mord mathnormal">t</span><span class="mopen">(</span><span class="mord mathnormal" style="margin-right:0.03148em;">k</span><span class="mord mathnormal" style="margin-right:0.03588em;">ey</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathnormal">s</span><span class="mord mathnormal">t</span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mclose">)</span></span></span></span>   如果没找到  <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>k</mi><mi>e</mi><mi>y</mi></mrow><annotation encoding="application/x-tex">key</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal" style="margin-right:0.03148em;">k</span><span class="mord mathnormal" style="margin-right:0.03588em;">ey</span></span></span></span>，则返回指定的默认值 <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>s</mi><mi>t</mi><mi>r</mi></mrow><annotation encoding="application/x-tex">str</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6151em;"></span><span class="mord mathnormal">s</span><span class="mord mathnormal">t</span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span></span></span></span>，如果没指定默认值，则返回 <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>N</mi><mi>o</mi><mi>n</mi><mi>e</mi></mrow><annotation encoding="application/x-tex">None</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6833em;"></span><span class="mord mathnormal" style="margin-right:0.10903em;">N</span><span class="mord mathnormal">o</span><span class="mord mathnormal">n</span><span class="mord mathnormal">e</span></span></span></span></li>
</ul>
<h3 id="练习6-1、练习6-2">练习6.1、练习6.2</h3>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs python">dic = &#123;<br>    <span class="hljs-string">&quot;first_name&quot;</span>: <span class="hljs-string">&quot;hu&quot;</span>,<br>    <span class="hljs-string">&quot;last_name&quot;</span>: <span class="hljs-string">&quot;guang cheng&quot;</span>,<br>    <span class="hljs-string">&quot;age&quot;</span>: <span class="hljs-number">18</span>,<br>    <span class="hljs-string">&quot;city&quot;</span>: <span class="hljs-string">&quot;hubei&quot;</span><br>&#125;<br><span class="hljs-built_in">print</span>(dic)<br>num_1 = &#123;<span class="hljs-string">&quot;tom&quot;</span>: <span class="hljs-number">1</span>, <span class="hljs-string">&quot;jerry&quot;</span>: <span class="hljs-number">2</span>, <span class="hljs-string">&quot;hgc&quot;</span>: <span class="hljs-number">6</span>, <span class="hljs-string">&quot;shu ke&quot;</span>: <span class="hljs-number">7</span>, <span class="hljs-string">&quot;jiu ge&quot;</span>: <span class="hljs-number">9</span>&#125;<br><span class="hljs-keyword">for</span> key, value <span class="hljs-keyword">in</span> num_1.items():<br>    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;<span class="hljs-subst">&#123;key&#125;</span> like <span class="hljs-subst">&#123;value&#125;</span>&quot;</span>)<br></code></pre></td></tr></table></figure>
<h3 id="练习6-5">练习6.5</h3>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs python">river = &#123;<br>    <span class="hljs-string">&quot;nile&quot;</span>: <span class="hljs-string">&quot;egypt&quot;</span>,<br>    <span class="hljs-string">&quot;river2&quot;</span>: <span class="hljs-string">&quot;country2&quot;</span>,<br>    <span class="hljs-string">&quot;river3&quot;</span>: <span class="hljs-string">&quot;country3&quot;</span><br>&#125;<br><span class="hljs-keyword">for</span> river_name, county_name <span class="hljs-keyword">in</span> river.items():<br>    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;the <span class="hljs-subst">&#123;river_name&#125;</span> runs through <span class="hljs-subst">&#123;county_name&#125;</span>&quot;</span>)<br><span class="hljs-keyword">for</span> river_name <span class="hljs-keyword">in</span> river.keys():<br>    <span class="hljs-built_in">print</span>(river_name)<br><span class="hljs-keyword">for</span> county_name <span class="hljs-keyword">in</span> river.values():<br>    <span class="hljs-built_in">print</span>(county_name)<br></code></pre></td></tr></table></figure>
<h3 id="练习6-6">练习6.6</h3>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><code class="hljs python">favorite_languages = &#123;<br>    <span class="hljs-string">&quot;jen&quot;</span>: <span class="hljs-string">&quot;python&quot;</span>,<br>    <span class="hljs-string">&quot;sarah&quot;</span>: <span class="hljs-string">&quot;c&quot;</span>,<br>    <span class="hljs-string">&quot;tom&quot;</span>: <span class="hljs-string">&quot;rust&quot;</span>,<br>    <span class="hljs-string">&quot;hgc&quot;</span>: <span class="hljs-string">&quot;java&quot;</span>,<br>    <span class="hljs-string">&quot;jerry&quot;</span>: <span class="hljs-string">&quot;python&quot;</span><br>&#125;<br>user_name = [<span class="hljs-string">&quot;tom&quot;</span>, <span class="hljs-string">&quot;shu ke&quot;</span>, <span class="hljs-string">&quot;bei ta&quot;</span>, <span class="hljs-string">&quot;hgc&quot;</span>]<br><span class="hljs-keyword">for</span> user <span class="hljs-keyword">in</span> user_name:<br>    <span class="hljs-keyword">if</span> user <span class="hljs-keyword">in</span> favorite_languages.keys():<br>        <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;thanks!<span class="hljs-subst">&#123;user&#125;</span>&quot;</span>)<br>    <span class="hljs-keyword">else</span>:<br>        <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;invite you!!<span class="hljs-subst">&#123;user&#125;</span>&quot;</span>)<br></code></pre></td></tr></table></figure>
<h3 id="练习6-7">练习6.7</h3>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><code class="hljs python">p1 = &#123;<br>    <span class="hljs-string">&quot;first_name&quot;</span>: <span class="hljs-string">&quot;hu&quot;</span>,<br>    <span class="hljs-string">&quot;last_name&quot;</span>: <span class="hljs-string">&quot;guang cheng&quot;</span>,<br>    <span class="hljs-string">&quot;age&quot;</span>: <span class="hljs-number">18</span>,<br>    <span class="hljs-string">&quot;city&quot;</span>: <span class="hljs-string">&quot;hubei&quot;</span><br>&#125;<br>p2 = &#123;<br>    <span class="hljs-string">&quot;first_name&quot;</span>: <span class="hljs-string">&quot;tom&quot;</span>,<br>    <span class="hljs-string">&quot;last_name&quot;</span>: <span class="hljs-string">&quot;jack&quot;</span>,<br>    <span class="hljs-string">&quot;age&quot;</span>: <span class="hljs-number">22</span>,<br>    <span class="hljs-string">&quot;city&quot;</span>: <span class="hljs-string">&quot;guang xi&quot;</span><br>&#125;<br>p3 = &#123;<br>    <span class="hljs-string">&quot;first_name&quot;</span>: <span class="hljs-string">&quot;shu ke&quot;</span>,<br>    <span class="hljs-string">&quot;last_name&quot;</span>: <span class="hljs-string">&quot;lin&quot;</span>,<br>    <span class="hljs-string">&quot;age&quot;</span>: <span class="hljs-number">20</span>,<br>    <span class="hljs-string">&quot;city&quot;</span>: <span class="hljs-string">&quot;shang hai&quot;</span><br>&#125;<br>people = [p1, p2, p3]<br><span class="hljs-keyword">for</span> p <span class="hljs-keyword">in</span> people:<br>    <span class="hljs-built_in">print</span>(p)<br></code></pre></td></tr></table></figure>
<h3 id="练习6-8">练习6.8</h3>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><code class="hljs python">pet1 = &#123;<br>    <span class="hljs-string">&quot;type&quot;</span>: <span class="hljs-string">&quot;dog&quot;</span>,<br>    <span class="hljs-string">&quot;owner&quot;</span>: <span class="hljs-string">&quot;shu ke&quot;</span><br>&#125;<br>pet2 = &#123;<br>    <span class="hljs-string">&quot;type&quot;</span>: <span class="hljs-string">&quot;cat&quot;</span>,<br>    <span class="hljs-string">&quot;owner&quot;</span>: <span class="hljs-string">&quot;bei ta&quot;</span><br>&#125;<br>pet3 = &#123;<br>    <span class="hljs-string">&quot;type&quot;</span>: <span class="hljs-string">&quot;pig&quot;</span>,<br>    <span class="hljs-string">&quot;owner&quot;</span>: <span class="hljs-string">&quot;hgc&quot;</span><br>&#125;<br>pets = [pet1, pet2, pet3]<br><span class="hljs-keyword">for</span> pet <span class="hljs-keyword">in</span> pets:<br>    <span class="hljs-built_in">print</span>(pet)<br></code></pre></td></tr></table></figure>
<h3 id="练习6-9">练习6.9</h3>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><code class="hljs python">favorite_place = &#123;<br>    <span class="hljs-string">&quot;hgc&quot;</span>: [],<br>    <span class="hljs-string">&quot;tom&quot;</span>: []<br>&#125;<br><span class="hljs-keyword">while</span> <span class="hljs-number">1</span>:<br>    <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;who are you?&quot;</span>)<br>    name = <span class="hljs-built_in">input</span>()<br>    <span class="hljs-keyword">if</span> name == <span class="hljs-string">&quot;quit&quot;</span>:<br>        <span class="hljs-keyword">break</span><br>    names = favorite_place.keys()<br>    <span class="hljs-keyword">if</span> name <span class="hljs-keyword">not</span> <span class="hljs-keyword">in</span> names:<br>        favorite_place[name] = []<br>    <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;what place do you like?&quot;</span>)<br>    favorite_place[name] = <span class="hljs-built_in">input</span>().split(<span class="hljs-string">&quot; &quot;</span>)<br><br><span class="hljs-keyword">for</span> user, places <span class="hljs-keyword">in</span> favorite_place.items():<br>    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;user:<span class="hljs-subst">&#123;user&#125;</span>  likes:&quot;</span>)<br>    <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> places:<br>        <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;no data!&quot;</span>)<br>    <span class="hljs-keyword">for</span> place <span class="hljs-keyword">in</span> places:<br>        <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;- <span class="hljs-subst">&#123;place&#125;</span>&quot;</span>)<br></code></pre></td></tr></table></figure>
<h3 id="练习6-10">练习6.10</h3>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs python">num_1 = &#123;<span class="hljs-string">&quot;tom&quot;</span>: [<span class="hljs-number">1</span>], <span class="hljs-string">&quot;jerry&quot;</span>: [<span class="hljs-number">3</span>, <span class="hljs-number">2</span>], <span class="hljs-string">&quot;hgc&quot;</span>: [<span class="hljs-number">6</span>, <span class="hljs-number">6</span>, <span class="hljs-number">6</span>], <span class="hljs-string">&quot;shu ke&quot;</span>: [<span class="hljs-number">7</span>, <span class="hljs-number">8</span>, <span class="hljs-number">9</span>], <span class="hljs-string">&quot;jiu ge&quot;</span>: [<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">7</span>]&#125;<br><span class="hljs-keyword">for</span> user, nums <span class="hljs-keyword">in</span> num_1.items():<br>    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;<span class="hljs-subst">&#123;user&#125;</span> like:&quot;</span>)<br>    <span class="hljs-keyword">for</span> num <span class="hljs-keyword">in</span> nums:<br>        <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;- <span class="hljs-subst">&#123;num&#125;</span>&quot;</span>)<br></code></pre></td></tr></table></figure>
<h3 id="练习6-11">练习6.11</h3>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><code class="hljs python">cities = &#123;<br>    <span class="hljs-string">&quot;shang hai&quot;</span>: &#123;<br>        <span class="hljs-string">&quot;belong_country&quot;</span>: <span class="hljs-string">&quot;china&quot;</span>,<br>        <span class="hljs-string">&quot;population&quot;</span>: <span class="hljs-number">1000000</span>,<br>        <span class="hljs-string">&quot;statement&quot;</span>: <span class="hljs-string">&quot;fact1&quot;</span><br>    &#125;,<br>    <span class="hljs-string">&quot;tokyo&quot;</span>: &#123;<br>        <span class="hljs-string">&quot;belong_country&quot;</span>: <span class="hljs-string">&quot;japan&quot;</span>,<br>        <span class="hljs-string">&quot;population&quot;</span>: <span class="hljs-number">2000000</span>,<br>        <span class="hljs-string">&quot;statement&quot;</span>: <span class="hljs-string">&quot;fact2&quot;</span><br>    &#125;,<br>    <span class="hljs-string">&quot;niu yue&quot;</span>: &#123;<br>        <span class="hljs-string">&quot;belong_country&quot;</span>: <span class="hljs-string">&quot;us&quot;</span>,<br>        <span class="hljs-string">&quot;population&quot;</span>: <span class="hljs-number">3000000</span>,<br>        <span class="hljs-string">&quot;statement&quot;</span>: <span class="hljs-string">&quot;fact3&quot;</span><br>    &#125;<br>&#125;<br><span class="hljs-keyword">for</span> city, info <span class="hljs-keyword">in</span> cities.items():<br>    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;<span class="hljs-subst">&#123;city&#125;</span>  info:&quot;</span>)<br>    <span class="hljs-keyword">for</span> key, val <span class="hljs-keyword">in</span> info.items():<br>        <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;- <span class="hljs-subst">&#123;key&#125;</span> : <span class="hljs-subst">&#123;val&#125;</span>&quot;</span>)<br></code></pre></td></tr></table></figure>

                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/python/" class="category-chain-item">python</a>
  
  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/tags/python%E5%85%A5%E9%97%A8/" class="print-no-link">#python入门</a>
      
        <a href="/tags/python%E5%AE%9E%E8%B7%B5/" class="print-no-link">#python实践</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>Python编程从入门到实践练习题</div>
      <div>http://example.com/2024/03/28/Python编程从入门到实践练习题/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>hgc</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2024年3月28日</div>
        </div>
      
      
      
        <div class="license-meta-item">
          <div>许可协议</div>
          <div>
            
              
              
                <a class="print-no-link" target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
                  <span class="hint--top hint--rounded" aria-label="BY - 署名">
                    <i class="iconfont icon-by"></i>
                  </span>
                </a>
              
            
          </div>
        </div>
      
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2024/03/28/python%E5%85%A5%E9%97%A8%E5%88%B7%E9%A2%98/" title="python入门刷题">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">python入门刷题</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2024/03/26/%E5%85%AD%E7%BA%A7%E5%A4%87%E8%80%83/" title="六级备考">
                        <span class="hidden-mobile">六级备考</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
  
  
    <article id="comments" lazyload>
      
  <div id="valine"></div>
  <script type="text/javascript">
    Fluid.utils.loadComments('#valine', function() {
      Fluid.utils.createScript('https://lib.baomitu.com/valine/1.5.1/Valine.min.js', function() {
        var options = Object.assign(
          {"appId":"ExOr1FY8NzdDhfdZvDw9D5c2-gzGzoHsz","appKey":"k7IRTVgwpZstqPIhmLpn9lvL","path":"window.location.pathname","placeholder":null,"avatar":"retro","meta":["nick","mail","link"],"requiredFields":[],"pageSize":10,"lang":"zh-CN","highlight":false,"recordIP":false,"serverURLs":"","emojiCDN":null,"emojiMaps":null,"enableQQ":false},
          {
            el: "#valine",
            path: window.location.pathname
          }
        )
        new Valine(options);
        Fluid.utils.waitElementVisible('#valine .vcontent', () => {
          var imgSelector = '#valine .vcontent img:not(.vemoji)';
          Fluid.plugins.imageCaption(imgSelector);
          Fluid.plugins.fancyBox(imgSelector);
        })
      });
    });
  </script>
  <noscript>Please enable JavaScript to view the comments</noscript>


    </article>
  


          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header">
    <i class="iconfont icon-list"></i>
    <span>目录</span>
  </p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  


  
  








    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
	  <!--《添加网站运行时间 -->
<br/>

<span id="timeDate">载入天数...</span><span id="times">载入时分秒...</span>
<script>
var now = new Date(); 

function createtime() {
    //此处修改你的建站时间或者网站上线时间
    var grt = new Date('02/07/2024 8:00:00');
    now.setTime(now.getTime() + 250);
    days = (now - grt) / 1000 / 60 / 60 / 24;

    dnum = Math.floor(days);
    hours = (now - grt) / 1000 / 60 / 60 - (24 * dnum);
    hnum = Math.floor(hours);
    if (String(hnum).length == 1) {
        hnum = "0" + hnum;
    }
    minutes = (now - grt) / 1000 / 60 - (24 * 60 * dnum) - (60 * hnum);
    mnum = Math.floor(minutes);
    if (String(mnum).length == 1) {
        mnum = "0" + mnum;
    }
    seconds = (now - grt) / 1000 - (24 * 60 * 60 * dnum) - (60 * 60 * hnum) - (60 * mnum);
    snum = Math.round(seconds);
    if (String(snum).length == 1) {
        snum = "0" + snum;
    }
    document.getElementById("timeDate").innerHTML = " 本小站已卧薪尝胆 " + dnum + " 天 ";
    document.getElementById("times").innerHTML = hnum + " 小时 " + mnum + " 分 " + snum + " 秒";
}
setInterval("createtime()", 250);
</script>

<!-- 添加网站运行时间》-->

    </div>
  
  
    <div class="statistics">
  
  

  
    
      <span id="leancloud-site-pv-container" style="display: none">
        总访问量 
        <span id="leancloud-site-pv"></span>
         次
      </span>
    
    
      <span id="leancloud-site-uv-container" style="display: none">
        总访客数 
        <span id="leancloud-site-uv"></span>
         人
      </span>
    
    

  
</div>

  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.4/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  var relativeDate = function() {
    var updatedTime = document.getElementById('updated-time');
    if (updatedTime) {
      var text = updatedTime.textContent;
      var reg = /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:Z|[+-]\d{2}:\d{2})/;
      var matchs = text.match(reg);
      if (matchs) {
        var relativeTime = moment(matchs[0]).fromNow();
        updatedTime.textContent = text.replace(reg, relativeTime);
      }
      updatedTime.style.display = '';
    }
  };
  Fluid.utils.createScript('https://lib.baomitu.com/moment.js/2.29.4/moment.min.js', function() {
    if (!'zh-cn'.startsWith('en')) {
      Fluid.utils.createScript('https://lib.baomitu.com/moment.js/2.29.4/locale/zh-cn.min.js', function() {
        relativeDate();
      });
    } else {
      relativeDate();
    }
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.20.1/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init(Object.assign({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      scrollSmooth    : true,
      includeTitleTags: true,
      headingsOffset  : -boardTop,
    }, CONFIG.toc));
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }

    Fluid.events.registerRefreshCallback(function() {
      if ('tocbot' in window) {
        tocbot.refresh();
        var toc = jQuery('#toc');
        if (toc.length === 0 || !tocbot) {
          return;
        }
        if (toc.find('.toc-list-item').length > 0) {
          toc.css('visibility', 'visible');
        }
      }
    });
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.11/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));

    Fluid.events.registerRefreshCallback(function() {
      if ('anchors' in window) {
        anchors.removeAll();
        var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
        var res = [];
        for (var item of el) {
          res.push('.markdown-body > ' + item.trim());
        }
        if (CONFIG.anchorjs.placement === 'left') {
          anchors.options.class = 'anchorjs-link-left';
        }
        anchors.add(res.join(', '));
      }
    });
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script defer src="/js/leancloud.js" ></script>

  <script  src="/js/local-search.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"log":false,"pluginJsPath":"lib/","pluginModelPath":"assets/","pluginRootPath":"live2dw/","tagMode":false});</script></body>
</html>
